﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using System.Configuration;
using TGIApp.Model;

namespace TGIApp.Web.Controllers
{
    public class VenueController : Controller
    {
        //
        // GET: /Venue/

        public ActionResult Index()
        {
            //var context = new TicketsModelContainer(new Uri(ConfigurationManager.AppSettings["DataServiceUri"]));
            //var venues = context.Venues.Expand("Address");
            //return View(venues);
            return View();
        }

        //
        // GET: /Venue/Details/5

        public ActionResult Details(int id)
        {
            //var context = new TicketsModelContainer(new Uri(ConfigurationManager.AppSettings["DataServiceUri"]));
            //var venue = context.Venues.Expand("Address").Where(v => v.Id == id).FirstOrDefault();

            //return View(venue);
            return View();
        }

        //
        // GET: /Venue/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Venue/Create

        [HttpPost]
        public ActionResult Create(Venue venue)
        {
            //var context = new TicketsModelContainer(new Uri(ConfigurationManager.AppSettings["DataServiceUri"]));
            //context.AddToAddresses(venue.Address);
            //context.AddToVenues(venue);
            //context.SetLink(venue, "Address", venue.Address);
            //context.SaveChanges(System.Data.Services.Client.SaveChangesOptions.Batch);
            //return RedirectToAction("Index");
            return View();
        }

        //
        // GET: /Venue/Edit/5

        public ActionResult Edit(int id)
        {
            //var context = new TicketsModelContainer(new Uri(ConfigurationManager.AppSettings["DataServiceUri"]));
            //var venue = context.Venues.Expand("Address").Where(v => v.Id == id).FirstOrDefault();
            //return View(venue);
            return View();
        }

        //
        // POST: /Venue/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, Venue venue)
        {
            //if (ModelState.IsValid)
            //{
            //    var context = new TicketsModelContainer(new Uri(ConfigurationManager.AppSettings["DataServiceUri"]));
            //    context.AttachTo("Venues", venue);
            //    context.AttachTo("Addresses", venue.Address);
            //    context.UpdateObject(venue.Address);
            //    context.UpdateObject(venue);

            //    context.SaveChanges(System.Data.Services.Client.SaveChangesOptions.Batch);

            //}

            //return RedirectToAction("Index");
            return View();
        }

        //
        // GET: /Venue/Delete/5

        public ActionResult Delete(int id)
        {
            //var context = new TicketsModelContainer(new Uri(ConfigurationManager.AppSettings["DataServiceUri"]));
            //var venue = context.Venues.Expand("Address").Where(v => v.Id == id).FirstOrDefault();
            //return View(venue);
            return View();
        }

        //
        // POST: /Venue/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, Venue venueToBeDeleted)
        {
            //var context = new TicketsModelContainer(new Uri(ConfigurationManager.AppSettings["DataServiceUri"]));
            //var venue = context.Venues.Expand("Address").Where(v => v.Id == id).FirstOrDefault();

            //context.DeleteObject(venue);
            //context.DeleteObject(venue.Address);
            //context.SaveChanges( System.Data.Services.Client.SaveChangesOptions.Batch);
            //return RedirectToAction("Index");
            return View();


        }
    }
}
